from native cimport *

from cache cimport Cacheable
from cycliclist cimport CyclicList
from iterators cimport BufferingIterator

cdef class Vertex(CyclicList):
    cdef int num_loops(self)

cdef class EqualIfIsomorphic(Cacheable):
    cdef readonly invariants
    cdef dict _cache_eq

cdef class BoundaryCycle(frozenset):
    cdef origin  # weakref proxy to Fatgraph
    cpdef transform(self, iso)

cdef class Fatgraph(EqualIfIsomorphic):
    cdef __weakref__
    cdef readonly list _cache_bcys
    cdef readonly dict _cache_edge_orbits
    cdef readonly dict _cache_edge_pair_orbits
    cdef readonly dict _cache_isomorphisms
    cdef readonly dict _cache_valence_spectrum
    cdef readonly int num_edges
    cdef readonly int num_external_edges
    cdef readonly int num_vertices
    cdef readonly list edge_numbering
    cdef readonly list endpoints_i
    cdef readonly list endpoints_v
    cdef readonly list vertices
    cpdef list automorphisms(self)
    cpdef list boundary_cycles(self)
    cdef int _cmp_orient(self, Fatgraph other, iso)
    cdef bridge(self, int edge1, int side1, int edge2, int side2)
    cdef Fatgraph contract_fg(self, int edgeno)
    cdef dict edge_orbits(self)
    cdef dict edge_pair_orbits(self)
    cpdef int genus(self)
    cdef Fatgraph hangcircle(self, int edge, int side)
    cpdef bool is_loop(self, int edge)
    cpdef bool is_orientation_reversing(self, automorphism)
    cpdef bool is_oriented(self)
    cpdef list isomorphisms(g1, g2)
    cpdef int num_automorphisms(self)
    cpdef int num_boundary_cycles(self)
    cdef other_end(graph, int edge, vertex, int attachment)
    cpdef int projection(self, other)
    cpdef dict valence_spectrum(self)
    cpdef frozenset vertex_valences(self)
    cpdef dict vertex_valence_distribution(self)

cdef starting_vertices(Fatgraph graph)
cdef bool compatible(Vertex v1, Vertex v2)
cdef list admissible_vertex_mappings(Vertex v, Fatgraph g, list ixs)
cdef extend_map(m, Fatgraph g1, int i1, int r, Fatgraph g2, int i2)
cdef list neighbors(m, Fatgraph g1, int i1, Fatgraph g2, int i2)

cdef bool append_if_no_duplicate(list lst, item)
cdef bool _admissible(Fatgraph G, int g, int n)
cpdef list MgnTrivalentGraphsRecursiveGenerator(int g, int n)

cdef class MgnGraphsIterator(BufferingIterator):
    cdef readonly int g
    cdef readonly int n
    cdef readonly int _num_vertices
    cdef list _batch
    cdef list refill(self)

cdef bool unseen(candidate, K, already)
cpdef list MakeNumberedGraphs(graph)

cdef class NumberedFatgraph(Fatgraph):
    cpdef readonly Fatgraph underlying
    cpdef readonly dict numbering
    cdef NumberedFatgraph contract_nfg(self, int edgeno)
    cpdef list isomorphisms(self, other)

cdef class MgnNumberedGraphsIterator(BufferingIterator):
    cdef __naked_graphs_iterator
    cdef list refill(self)
